/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-05 09:45:52
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-05 10:02:31
 * @Description: file content
 */

#include "apue.h"

int globvar = 6;
char buf[] = "a write to stdout\n";

int main()
{
    int var = 88;
    pid_t pid;

    int writeLen = write(STDOUT_FILENO, buf, sizeof(buf) -1);
    if (writeLen != sizeof(buf) -1)
    {
        err_sys("write error");
    }

    printf("before fork\n");
    if ((pid = fork()) < 0)
    {
        err_sys("fork error");
    }
    else if (0 == pid) // 子进程
    {
        globvar++;
        var++;
    }
    else
    {
        sleep(2);
    }

    printf("pid = %ld, glob = %d, var = %d\n", (long)getpid(), globvar, var);
    exit(0);
}
